/**
 * 
 */
package com.td.framework.webmanager.yhz.action;


import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import com.td.framework.common.AbstractAction;
import com.td.framework.common.Constant;
import com.td.framework.webmanager.dlyh.service.DlyhService;
import com.td.framework.webmanager.domain.AppsysDlyhBean;
import com.td.framework.webmanager.domain.AppsysQxfwjlgx;
import com.td.framework.webmanager.domain.AppsysQxygns;
import com.td.framework.webmanager.domain.AppsysYhz;
import com.td.framework.webmanager.domain.AppsysYmgnBean;
import com.td.framework.webmanager.domain.AppsysYmxzfwjlBean;
import com.td.framework.webmanager.domain.YmxztjBean;
import com.td.framework.webmanager.qxgl.service.QxglService;
import com.td.framework.webmanager.yhz.service.YhzService;
import com.opensymphony.xwork2.Action;

/**
 * 
 * Title:处理用户组信息Action
 *  Description:处理用户组信息 
 *  Copyright: Copyright (c) 2008 
 *  Company 北京水软科技有限公司
 * @version 1.0
 */
public class YhzAction extends AbstractAction implements Action {
	private static final long serialVersionUID = -2567577981992496242L;
	private YhzService yhzService = null;// 用户组业务层接口;
	private QxglService qxglService = null;// 权限处理业务层接口;
	private List<AppsysYhz> yhzList = null;// 用户组list;
	private AppsysYhz appsysYhz = null;// 用户组;
	private String yhzbhs = "";// 用户组编号组;
	private String yhzbh = null;// 用户组编号;
	private String target = "";// 返回参数;
	private String sysTreeXml = "";// 系统权限树xml字符流;
	private String yhzTreeXml = "";// 用户组当前系统权限树xml字符流;
	private String[] ymbhs = null;//页面编号,授权时用;
	private List<AppsysQxygns>  rightTreeList = null;//用户组当前权限List;
	private List<AppsysYmgnBean> appsysYmgnBeanList = null;//页面功能List;
	private List<AppsysYmgnBean> xzzdList = null;// 限制字段List;
	private List<AppsysYmxzfwjlBean> fwjlList = null;//限制访问记录List;
	private List<AppsysQxfwjlgx> qxfwjlgxs = null;//权限与限制访问记录关系数组;
	private List<YmxztjBean> ymxztjList = null;//限制条件List;
	private String xzbh = "";//限制编号,选择条件用;
	private Long qxbh = null;//权限编号;
	private String [] gnbhs = null;//功能编号与权限标志组合数组;
	private String urlFlag = "";//区分字段,授权是区分是点击下一步还是完成;
	private DlyhService dlyhService = null;//登录用户业务层接口;
	private List<AppsysDlyhBean> dlyhList = null;//用户List;
	private List<AppsysDlyhBean> currDlyhList = null;//当前用户组用户List;
	private String yhbhs = "";//用户组当前用户编号;
	private Timestamp timeStamp= null;
	/**
	 * @toDo:通过用户组名称查询用户组列表;
	 * @return target;
	 */
	public String listYhz() {
		yhzService.setSql(appsysYhz);
		int rows = yhzService.getRows();
		page = this.pageService.getPage(rows, currentPage, pageSize, pageMethod);
		this.setCurrentPage(page.getCurentPage());		
		this.setPageSize(page.getPageSize());
		yhzList = yhzService.findByYhzm(page.getPageSize(), page.getStartRow());
		target = "list";
		return target;
	}

	/**
	 * @toDo:查询用户组对象;
	 * @return target;
	 */
	public String InfoYhz() {
		appsysYhz = yhzService.getAppsysYhz(Long.parseLong(yhzbh));
		target = "info";
		return target;
	}

	/**
	 * @toDo:生成授权所需的Xml字符流;
	 * @return target;
	 */
	public String createXmlTree() {
		sysTreeXml = qxglService.getCurrentTreeXml("system",yhzbh,new Long(0),1);
		yhzTreeXml = qxglService.getCurrentTreeXml("my",yhzbh,new Long(0),0);
		target = "rightTree";
		return target;
	}
	
	/**
	 * @toDo:生成用户组当前权限树;
	 * @return target;
	 */
	public String  createRightTree()
	{
		rightTreeList = qxglService.getRightTreeList(yhzbh+"",new Long(0),2);
		qxbh=qxglService.getQxbh(yhzbh+"",new Long(0));
		target = "rightTree";
		return target;
	}
	/**
	 * @toDo:生成页面级功能页面
	 * @return target;
	 */
	@SuppressWarnings("unchecked")
	public String createYmgns()
	{
		appsysYmgnBeanList = new ArrayList();
		xzzdList = new ArrayList();
		if (qxbh != null && ymbhs != null) {
			appsysYmgnBeanList = qxglService.findAppsysYmgnBean(qxbh, ymbhs[0],1);
			xzzdList = qxglService.findAppsysYmgnBean(qxbh, ymbhs[0], 2);
			fwjlList = qxglService.findAppsysYmxzfwjlBean(qxbh, ymbhs[0]);
		}
		target = "ymgns";
		return target;
	}
	/**
	 * @toDo:用户组页面级功能授权保存;
	 * @return target;
	 */
	public String  changeYmgnRight()
	{
		if(qxglService.addYmgnRight(qxbh+"", ymbhs[0], gnbhs,qxfwjlgxs))
		{
			this.handleMessage("info", "授权成功,请继续操作!");
			target = "changeSuccess";
		}
		else
		{
			this.handleMessage("info", "授权失败,请重新操作!");
			target = "changeFailure";
		}
		appsysYmgnBeanList=qxglService.findAppsysYmgnBean(qxbh, ymbhs[0],1);
		xzzdList = qxglService.findAppsysYmgnBean(qxbh, ymbhs[0], 2);
		fwjlList = qxglService.findAppsysYmxzfwjlBean(qxbh, ymbhs[0]);
		return target;
	}
	/**
	 * @toDo:生成用户组添加表单;
	 * @return target;
	 */
	public String createYhzForm() {
		target = "createForm";
		return target;
	}

	/**
	 * @toDo:保存用户组信息;
	 * @return target;
	 */
	public String createYhz() {
		if(getUserInfo()!=null)
		{
			appsysYhz.setCjr(getUserInfo().getYhm());
		}
		if (yhzService.addAppsysYhz(appsysYhz))
		{
			this.handleMessage("info", "添加成功,请继续操作!");
			appsysYhz =null;
			target = "addSuccess";
		}
		else
		{
			this.handleMessage("info", "添加失败,您添加的信息不符合要求,请重新添加!");
			target = "addFailure";
		}
		return target;
	}

	/**
	 * @toDo:生成用户组编辑表单;
	 * @return target;
	 */
	public String reworkYhzForm() {

		appsysYhz = yhzService.getAppsysYhz(Long
				.parseLong(yhzbhs.split(",")[0]));
		if (appsysYhz != null)
		{
			target = "reworkForm";
		}
		else
		{
			target = "list";
		}
		return target;
	}

	/**
	 * @toDo:更新用户组信息;
	 * @return 用户组;
	 */
	public String reworkYhz() {
		String result="";
		if (yhzService.updateAppsysYhz(appsysYhz))
		{
			target = "updateSuccess";
			result ="OK";
		}
		else
		{
			target = "updateFailure";
			this.handleMessage("info", "修改失败,请重新修改!");
			result ="failure";
		}
		return target;
	}

	/**
	 * @toDo:删除用户组信息;
	 * @return target;
	 */
	public String removeYhz() {
		yhzService.deleteAppsysYhz(yhzbhs.split(","));
		target = "deleteSuccess";
		return target;
	}
	
	/**
	 * @toDo:
	 * @return
	 */
	public String selYh()
	{
		dlyhList=dlyhService.findAppsysDlyhBeanByYhzbh(yhzbhs,1,this.getUserInfo().getYhbh(),Constant.SYS_XTBM,this.getUserInfo().getBmbh());
		currDlyhList=dlyhService.findAppsysDlyhBeanByYhzbh(yhzbhs,0,this.getUserInfo().getYhbh(),Constant.SYS_XTBM,this.getUserInfo().getBmbh());
		appsysYhz = yhzService.getAppsysYhz(Long.parseLong(yhzbhs));
		target = "selYh";
		return target;
	}
	/**
	 * @toDo:
	 * @return
	 */
	public String createSsYh()
	{
		if(yhzService.addAppsysYhYhzGx(yhbhs, yhzbhs, 1))
		{
			target = "addSuccess";
			this.handleMessage("info", "选择用户成功!");
		}
		else
		{
			target = "addFailure";
			this.handleMessage("info", "选择用户失败!");
		}
		this.handleMessage("isVisual","1");
		yhbhs="";
		return target;
	}
	/**
	 * @toDo:get用户组业务层接口 ;
	 * @return the yhzService
	 */
	public YhzService getYhzService() {
		return yhzService;
	}

	/**
	 * @toDo:set用户组业务层接口 ;
	 * @param yhzService
	 *            the yhzService to set
	 */
	public void setYhzService(YhzService yhzService) {
		this.yhzService = yhzService;
	}

	/**
	 * @toDo:get用户组List ;
	 * @return the yhzList
	 */
	@SuppressWarnings("unchecked")
	public List getYhzList() {
		return yhzList;
	}

	/**
	 * @toDo:set用户组List ;
	 * @param yhzList
	 *            the yhzList to set
	 */
	@SuppressWarnings("unchecked")
	public void setYhzList(List yhzList) {
		this.yhzList = yhzList;
	}

	/**
	 * @toDo:get用户组 ;
	 * @return the appsysYhz
	 */
	
	public AppsysYhz getAppsysYhz() {
		return appsysYhz;
	}

	/**
	 * @toDo:set用户组 ;
	 * @param appsysYhz
	 *            the appsysYhz to set
	 */
	public void setAppsysYhz(AppsysYhz appsysYhz) {
		this.appsysYhz = appsysYhz;
	}

	/**
	 * @toDo:get用户组编号组 ;
	 * @return the yhzbhs
	 */
	public String getYhzbhs() {
		return yhzbhs;
	}

	/**
	 * @toDo:set用户组编号组 ;
	 * @param yhzbhs
	 *            the yhzbhs to set
	 */
	public void setYhzbhs(String yhzbhs) {
		this.yhzbhs = yhzbhs;
	}

	/**
	 * @toDo:get用户编号 ;
	 * @return the yhzbh
	 */
	public String getYhzbh() {
		return yhzbh;
	}

	/**
	 * @toDo:set用户编号 ;
	 * @param yhzbh
	 *            the yhzbh to set
	 */
	public void setYhzbh(String yhzbh) {
		this.yhzbh = yhzbh;
	}

	/**
	 * @toDo:get目标参数 ;
	 * @return the target
	 */
	public String getTarget() {
		return target;
	}

	/**
	 * @toDo:se目标参数t ;
	 * @param target
	 *            the target to set
	 */
	public void setTarget(String target) {
		this.target = target;
	}

	/**
	 * @toDo:get权限处理业务层接口 ;
	 * @return the qxglService
	 */
	public QxglService getQxglService() {
		return qxglService;
	}

	/**
	 * @toDo:set权限处理业务层接口 ;
	 * @param qxglService
	 *            the qxglService to set
	 */
	public void setQxglService(QxglService qxglService) {
		this.qxglService = qxglService;
	}

	/**
	 * @toDo:get系统权限树xml字符流 ;
	 * @return the sysTreeXml
	 */
	public String getSysTreeXml() {
		return sysTreeXml;
	}

	/**
	 * @toDo:set系统权限树xml字符流 ;
	 * @param sysTreeXml
	 *            the sysTreeXml to set
	 */
	public void setSysTreeXml(String sysTreeXml) {
		this.sysTreeXml = sysTreeXml;
	}

	/**
	 * @toDo:get用户组当前系统权限树xml字符流 ;
	 * @return the yhzTreeXml
	 */
	public String getYhzTreeXml() {
		return yhzTreeXml;
	}

	/**
	 * @toDo:set用户组当前系统权限树xml字符流 ;
	 * @param yhzTreeXml
	 *            the yhzTreeXml to set
	 */
	public void setYhzTreeXml(String yhzTreeXml) {
		this.yhzTreeXml = yhzTreeXml;
	}

	/**
	 * @toDo:get页面编号 ;
	 * @return the ymbhs
	 */
	public String[] getYmbhs() {
		return ymbhs;
	}

	/**
	 * @toDo:set页面编号 ;
	 * @param ymbhs the ymbhs to set
	 */
	public void setYmbhs(String[] ymbhs) {
		this.ymbhs = ymbhs;
	}

	/**
	 * @toDo:get用户组当前权限List ;
	 * @return the rightTreeList
	 */
	public List<AppsysQxygns> getRightTreeList() {
		return rightTreeList;
	}

	/**
	 * @toDo:set用户组当前权限List ;
	 * @param rightTreeList the rightTreeList to set
	 */
	public void setRightTreeList(List<AppsysQxygns> rightTreeList) {
		this.rightTreeList = rightTreeList;
	}

	/**
	 * @toDo:get权限编号 ;
	 * @return the qxbh
	 */
	public Long getQxbh() {
		return qxbh;
	}

	/**
	 * @toDo:set权限编号 ;
	 * @param qxbh the qxbh to set
	 */
	public void setQxbh(Long qxbh) {
		this.qxbh = qxbh;
	}

	/**
	 * @toDo:get页面功能List ;
	 * @return the appsysYmgnVoList
	 */
	public List<AppsysYmgnBean> getAppsysYmgnBeanList() {
		return appsysYmgnBeanList;
	}

	/**
	 * @toDo:set页面功能List ;
	 * @param appsysYmgnVoList the appsysYmgnVoList to set
	 */
	public void setAppsysYmgnVoList(List<AppsysYmgnBean> appsysYmgnBeanList) {
		this.appsysYmgnBeanList = appsysYmgnBeanList;
	}

	/**
	 * @toDo:get功能编号与权限标志组合数组 ;
	 * @return the gnbhs
	 */
	public String[] getGnbhs() {
		return gnbhs;
	}

	/**
	 * @toDo:set功能编号与权限标志组合数组 ;
	 * @param gnbhs the gnbhs to set
	 */
	public void setGnbhs(String[] gnbhs) {
		this.gnbhs = gnbhs;
	}

	public String getUrlFlag() {
		return urlFlag;
	}

	public void setUrlFlag(String urlFlag) {
		this.urlFlag = urlFlag;
	}

	public Timestamp getTimeStamp() {
		return timeStamp;
	}

	public void setTimeStamp(Timestamp timeStamp) {
		Random ran = new Random();
		this.timeStamp =new Timestamp(ran.nextLong());
	}

	/**
	 * @toDo:get
	 * @return the dlyhService
	 */
	public DlyhService getDlyhService() {
		return dlyhService;
	}

	/**
	 * @toDo:set
	 * @param dlyhService the dlyhService to set
	 */
	public void setDlyhService(DlyhService dlyhService) {
		this.dlyhService = dlyhService;
	}

	/**
	 * @toDo:get
	 * @return the dlyhList
	 */
	public List<AppsysDlyhBean> getDlyhList() {
		return dlyhList;
	}

	/**
	 * @toDo:set
	 * @param dlyhList the dlyhList to set
	 */
	public void setDlyhList(List<AppsysDlyhBean> dlyhList) {
		this.dlyhList = dlyhList;
	}

	/**
	 * @toDo:get
	 * @return the currDlyhList
	 */
	public List<AppsysDlyhBean> getCurrDlyhList() {
		return currDlyhList;
	}

	/**
	 * @toDo:set
	 * @param currDlyhList the currDlyhList to set
	 */
	public void setCurrDlyhList(List<AppsysDlyhBean> currDlyhList) {
		this.currDlyhList = currDlyhList;
	}

	/**
	 * @toDo:get
	 * @return the yhbhs
	 */
	public String getYhbhs() {
		return yhbhs;
	}

	/**
	 * @toDo:set
	 * @param yhbhs the yhbhs to set
	 */
	public void setYhbhs(String yhbhs) {
		this.yhbhs = yhbhs;
	}

	/**
	 * toDo:get
	 * @return xzzdList
	 */
	public List<AppsysYmgnBean> getXzzdList() {
		return xzzdList;
	}

	/**
	 * toDo:set
	 * @param xzzdList 
	 */
	public void setXzzdList(List<AppsysYmgnBean> xzzdList) {
		this.xzzdList = xzzdList;
	}

	/**
	 * @return the fwjlList
	 */
	public List<AppsysYmxzfwjlBean> getFwjlList() {
		return fwjlList;
	}

	/**
	 * @param fwjlList the fwjlList to set
	 */
	public void setFwjlList(List<AppsysYmxzfwjlBean> fwjlList) {
		this.fwjlList = fwjlList;
	}

	/**
	 * @return the qxfwjlgxs
	 */
	public List<AppsysQxfwjlgx> getQxfwjlgxs() {
		return qxfwjlgxs;
	}

	/**
	 * @param qxfwjlgxs the qxfwjlgxs to set
	 */
	public void setQxfwjlgxs(List<AppsysQxfwjlgx> qxfwjlgxs) {
		this.qxfwjlgxs = qxfwjlgxs;
	}

	/**
	 * @return the ymxztjList
	 */
	public List<YmxztjBean> getYmxztjList() {
		return ymxztjList;
	}

	/**
	 * @param ymxztjList the ymxztjList to set
	 */
	public void setYmxztjList(List<YmxztjBean> ymxztjList) {
		this.ymxztjList = ymxztjList;
	}

	/**
	 * @return the xzbh
	 */
	public String getXzbh() {
		return xzbh;
	}

	/**
	 * @param xzbh the xzbh to set
	 */
	public void setXzbh(String xzbh) {
		this.xzbh = xzbh;
	}

	/**
	 * @param appsysYmgnBeanList the appsysYmgnBeanList to set
	 */
	public void setAppsysYmgnBeanList(List<AppsysYmgnBean> appsysYmgnBeanList) {
		this.appsysYmgnBeanList = appsysYmgnBeanList;
	}
}
